package com.gxg.newdemo1.mynewdamo1;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.gxg.newdemo1.mynewdamo1.HorizontalAnimalLayout.HorizontalAnimalLayoutActivity;
import com.gxg.newdemo1.mynewdamo1.VerticalTabLayout.VerticalTabLayoutTestActivity;
import com.gxg.newdemo1.mynewdamo1.ca.TestActivity;
import com.gxg.newdemo1.mynewdamo1.channel.ChannelActivity;
import com.gxg.newdemo1.mynewdamo1.channel.bean.ChannelItem;
import com.gxg.newdemo1.mynewdamo1.channel.bean.ChannelManage;
import com.gxg.newdemo1.mynewdamo1.channel.bean.HomeBean;
import com.gxg.newdemo1.mynewdamo1.channel.util.AssetsUtils;
import com.gxg.newdemo1.mynewdamo1.channel.util.GsonUtil;
import com.gxg.newdemo1.mynewdamo1.dayin.DayinActivty;
import com.gxg.newdemo1.mynewdamo1.signature.TestSPSAPIActivity;
import com.socks.library.KLog;
import com.yanzhenjie.permission.Action;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.Permission;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.org.bjca.signet.helper.bean.OCRInfoBean;
import cn.org.bjca.signet.sdk.OfflineSignResultEntity;
import cn.org.bjca.signet.sdk.ResultEntity;
import cn.org.bjca.signet.sdk.SignetCallBack;
import cn.org.bjca.signet.sdk.UserEntity;

public class MainActivity extends AppCompatActivity implements SignetCallBack {

    @BindView(R.id.tv_chanle_select)
    TextView tvChanleSelect;
    @BindView(R.id.tv_chanle_select1)
    TextView tvChanleSelect1;
    private ChannelManage manage;
    private HomeBean homeBean;
    private List<ChannelItem> userChannelList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);
        initPermission();
        manage = ChannelManage.getManage(BaseApplication.getInstance().getSQLHelper());

        manage.defaultOtherChannels = new ArrayList<ChannelItem>();
        manage.defaultUserChannels = new ArrayList<ChannelItem>();


        String string = AssetsUtils.getString("home.json", this);
        if(!TextUtils.isEmpty(string)){
            homeBean = GsonUtil.GsonToObject(string.trim(), HomeBean.class);
            KLog.e("sss  "+ homeBean.getRtData().getLoginFunc().size());
        }
        KLog.e("sss  "+string);
        if(homeBean!=null && homeBean.getRtData()!=null && homeBean.getRtData().getLoginFunc()!=null){
            for (int i = 0; i < homeBean.getRtData().getLoginFunc().size(); i++) {
                ChannelItem channelItem = new ChannelItem();
                channelItem.setName(homeBean.getRtData().getLoginFunc().get(i).getAppName());
                channelItem.setUad(1);
                channelItem.setSelected(0);
                channelItem.setIschange(0);
                channelItem.setRid(homeBean.getRtData().getLoginFunc().get(i).getSid()+"");
                channelItem.setType(1);
                channelItem.setImg(R.drawable.icon_office_default);
                channelItem.setPic(homeBean.getRtData().getLoginFunc().get(i).getPic());
                channelItem.setSid(homeBean.getRtData().getLoginFunc().get(i).getSid()+"");
                channelItem.setUrl(homeBean.getRtData().getLoginFunc().get(i).getUrl());
                channelItem.setPushNum(0);

                if(i<10){
                    manage.defaultUserChannels.add(channelItem);
                }else{
                    manage.defaultOtherChannels.add(channelItem);
                }
            }
            userChannelList = manage.getUserChannel();
            KLog.e("sss  "+userChannelList.size());
        }


    }

    private void initPermission() {
        AndPermission.with(this)
                .runtime()
                .permission(Permission.WRITE_EXTERNAL_STORAGE,Permission.READ_EXTERNAL_STORAGE,Permission.READ_PHONE_STATE)
                .onDenied(new Action<List<String>>() {
                    @Override
                    public void onAction(List<String> data) {
                        KLog.e("拒绝权限");
                    }
                })
                .onGranted(new Action<List<String>>() {
                    @Override
                    public void onAction(List<String> data) {
                        KLog.e("同意权限");
                    }
                })
                .start();
    }

    @OnClick({R.id.tv_ca,R.id.tv_dayin,R.id.tv_qianming,R.id.tv_chanle_select, R.id.tv_chanle_select1,R.id.tv_chanle_select2})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_chanle_select:
                startActivity(new Intent(MainActivity.this, ChannelActivity.class));
                break;
            case R.id.tv_chanle_select1:
                startActivity(new Intent(MainActivity.this, VerticalTabLayoutTestActivity.class));
                break;
            case R.id.tv_chanle_select2:
                startActivity(new Intent(MainActivity.this, HorizontalAnimalLayoutActivity.class));
                break;
            case R.id.tv_qianming:
                startActivity(new Intent(MainActivity.this, TestSPSAPIActivity.class));
                break;
            case R.id.tv_dayin:
                startActivity(new Intent(MainActivity.this, DayinActivty.class));
                break;
            case R.id.tv_ca:
                startActivity(new Intent(MainActivity.this, TestActivity.class));
                break;
        }
    }

    @Override
    public void loginCallBack(ResultEntity resultEntity) {
        KLog.e("sss  登录 "+resultEntity.getStatus());
    }

    @Override
    public void qrLoginCallBack(ResultEntity resultEntity) {

    }

    @Override
    public void registerCallBack(ResultEntity resultEntity) {
        KLog.e("sss  注册"+resultEntity.getStatus());
    }

    @Override
    public void qrRegisterCallBack(ResultEntity resultEntity) {

    }

    @Override
    public void signDataCallBack(ResultEntity resultEntity) {

    }

    @Override
    public void qrSignDataCallBack(ResultEntity resultEntity) {

    }

    @Override
    public void findBackUserCallBack(ResultEntity resultEntity) {
        KLog.e("sss  查询用户 "+resultEntity.getStatus());
    }

    @Override
    public void signDocuCallBack(ResultEntity resultEntity) {

    }

    @Override
    public void setHandWritingCallBack(ResultEntity resultEntity) {

    }

    @Override
    public void selfRegisterCallBack(ResultEntity resultEntity) {

    }

    @Override
    public void setFingerCallBack(ResultEntity resultEntity) {

    }

    @Override
    public void selfRegInfoCallBack(UserEntity userEntity) {

    }

    @Override
    public void selfRegGetOcrCallBack(OCRInfoBean ocrInfoBean) {

    }

    @Override
    public void enterPriseSealCallBack(ResultEntity resultEntity) {

    }

    @Override
    public void enterPriseSealSingleCallBack(ResultEntity resultEntity) {

    }

    @Override
    public void enterPriseSealImageSingleCallBack(ResultEntity resultEntity) {

    }

    @Override
    public void reqOfflineCertCallBack(ResultEntity resultEntity) {

    }

    @Override
    public void offlineSignCallBack(OfflineSignResultEntity offlineSignResultEntity) {

    }

    @Override
    public void getDocuInfoCallBack(ResultEntity resultEntity) {

    }
}
